package com.yisu.auction.manager.website.controller.memberInfo;

import com.yisu.auction.ewf.common.enums.ResponseCode;
import com.yisu.auction.ewf.common.web.EasyUIGrid;
import com.yisu.auction.ewf.common.web.JsonResult;
import com.yisu.auction.manager.core.service.IShowService;
import com.yisu.auction.manager.domain.request.ShowInfoPackage.ShareShowRequest;
import com.yisu.auction.manager.domain.vo.showInfoPackageVos.ShareShowVo;
import com.yisu.auction.manager.website.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.net.URLDecoder;

/**
 * author: 赵杰
 * Business Description：
 * createTime：2017/8/22
 */
@Controller
@RequestMapping(value = "/show")
public class ShowController extends BaseController {
    @Resource
    private IShowService iShowService;

    /**
     * author:黄萧林
     * Business Description:返回晒单管理页面
     * @param shareShowRequest
     * @param model
     * @return
     */
    @RequestMapping(value = "/index.htm")
    public String showIndex(ShareShowRequest shareShowRequest, Model model){
        try {
            if (shareShowRequest.getKeyword() != null) {
                shareShowRequest.setKeyword(URLDecoder.decode(shareShowRequest.getKeyword(), "utf-8"));
            }
            EasyUIGrid<ShareShowVo> showVoEasyUIGrid =iShowService.getShareOrderInfoByPage(shareShowRequest);
            model.addAttribute("ShareShowVos",showVoEasyUIGrid.getRows());
            model.addAttribute("currentPage",shareShowRequest.getPage());
            model.addAttribute("totalPages",(shareShowRequest.getTotalRecords() / shareShowRequest.getRows()) + 1);
            model.addAttribute("keyword",shareShowRequest.getKeyword());
        }catch (Exception e){
            logger.error("获取晒单列表页面" + e.getMessage());
        }
        return "/memberInfo/showInfo/index";
    }

    /**
     * author:黄萧林
     * Business Description:改变晒单状态
     * @param id
     * @return
     */
    @RequestMapping(value = "/ChangeStatus.json")
    @ResponseBody
    public JsonResult changeStatus(Long id) {
        try {
            if (iShowService.changeStatus(id)) {
                return new JsonResult();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new JsonResult(ResponseCode.FAILURE.code, "网络君泡妞去了！");
    }

}
